<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1"><!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
        <meta name="renderer" content="webkit"><!--国产浏览器高速模式-->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>
            花礼网-后台
        </title><!-- 公共样式 开始 -->
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/admin/css/base.css">
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/admin/css/iconfont.css">
        <script type="text/javascript" src="${pageContext.request.contextPath }/admin/framework/jquery-1.11.3.min.js"></script>
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/admin/layui/css/layui.css">
        <script type="text/javascript" src="${pageContext.request.contextPath }/admin/layui/layui.js"></script><!-- 滚动条插件 -->
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/admin/css/jquery.mCustomScrollbar.css">
        <script src=${pageContext.request.contextPath }/admin/framework/jquery-ui-1.10.4.min.js"></script>
        <script src="${pageContext.request.contextPath }/admin/framework/jquery.mousewheel.min.js"></script>
        <script src="${pageContext.request.contextPath }/admin/framework/jquery.mCustomScrollbar.min.js"></script>
        <script src="${pageContext.request.contextPath }/admin/framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
        <!-- 公共样式 结束 -->
    </head>
    <body>
        <div class="cBody">
            <div class="console">
                <span style="margin-left:30px;margin-right: 10px;">商品类型等级</span>
                <div class="layui-input-inline">
                    <input type="text" name="flag" lay-verify="required" placeholder="输入商品类型等级" autocomplete="off" class="layui-input">
                </div>
                <span style="margin-left:30px;margin-right: 10px;">商品类型名称</span>
                <div class="layui-input-inline">
                    <input type="text" name="name" lay-verify="required" placeholder="输入商品类型名称" autocomplete="off" class="layui-input">
                </div>
                <button class="layui-btn" lay-submit="" lay-filter="formDemo" id="search" style="margin-left: 50px;">检索</button>
            </div>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>类型</th>
                        <th>等级</th>
                        <th>所属类型</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${gtlist}" var="gtype" varStatus="i">
                        <tr>
                            <td>${i.count}</td>
                            <td>${gtype.name}</td>
                            <td>${gtype.level}</td>
                            <td>${gtype.parentName}</td>
                            <td>
                                <button class="layui-btn layui-btn-xs" onclick="deleteGoodsType(${gtype.id})">删除</button>
                            </td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table><!-- layUI 分页模块 -->
            <div id="pages"></div>
            <script>
                window.
                layui.use(['laypage', 'layer'], function() {
                        var laypage = layui.laypage,
                                layer = layui.layer;

                        //总页数大于页码总数
                        laypage.render({
                            elem: 'pages'
                            ,count: 100
                            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                            ,jump: function(obj){
                                console.log(obj)
                            }
                        });
                });
            </script>
        </div>
    </body>
    <script>
        //条件查询
        $(function () {
            //给查询按钮 添加 点击事件
            $("#search").click(function () {
                let flag = $("input[name='flag']").val();
                let name = $("input[name='name']").val();
                var url="";
<%--                <c:set var="flag">flag</c:set>--%>
<%--                <c:set var="name">name</c:set>--%>
                if (flag==''){
                    url = "${pageContext.request.contextPath}/adminSelectByName?name=" + name ;
                }else if (name==''){
                    url= "${pageContext.request.contextPath}/adminSelectByFlag?flag=" + flag ;
                }else {
                    url = "${pageContext.request.contextPath}/selectByNameAndFlag?flag=" + flag + "&name=" + name;
                }
                location.href = url;
            })
        })

        //删除数据
        function deleteGoodsType(count) {
            $.ajax({
                url: "${pageContext.request.contextPath}/deleteGoodsType",
                method: "get",
                data: {"count": count},
                success: function (data) {
                    location.href = "${pageContext.request.contextPath}/getGoodsType";
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
                }
            });
        }
    </script>
</html>